package com.yksj.healthtalk.ui;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.view.View.OnClickListener;

import com.yksj.healthtalk.comm.BaseFragmentActivity;
import com.yksj.healthtalk.ui.home.MyCommunityFragment;

/**
 * 社区(病友社区,我的社区)
 * 
 * @author jack_tang
 * 
 */
public class CommunityActivity extends BaseFragmentActivity implements
		OnClickListener {

	private int intExtra;//0 病友社区  1我的社区

	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		setContentView(R.layout.community_layout);

		if (arg0 != null) {
			intExtra = arg0.getInt("id", 1);
		} else {
			intExtra = getIntent().getIntExtra("id", 1);
		}

		initView();
	}

	private void initView() {
		initTitle();
		titleLeftBtn.setOnClickListener(this);
		Fragment fragment;
		if(intExtra == 0){//病友社区
			titleTextV.setText("病友社区");
			fragment = new PatientsCommunityFragment();
		}else{//我的社区
			titleTextV.setText("我的社区");
			fragment = new MyCommunityFragment();
		}
		FragmentManager fg = getSupportFragmentManager();
		FragmentTransaction ft = fg.beginTransaction();
		ft.replace(R.id.fragment,fragment);
		ft.commit();
	}

	@Override
	protected void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
		intExtra = outState.getInt("id", 1);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.title_back:
			onBackPressed();
			break;
		}

	}
}
